home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Programming / SWI / source / src / pl-global.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-26  |  9.1 KB  |  312 lines

  1. /*  $Id: pl-global.h,v 1.3 1997/08/26 10:08:49 jan Exp $
  2.  
  3.     Part of SWI-Prolog
  4.     Designed and implemented by Jan Wielemaker
  5.     E-mail: jan@swi.psy.uva.nl
  6.  
  7.     Copyright (C) 1997 University of Amsterdam. All rights reserved.
  8. */
  9.  
  10. #ifndef PL_GLOBAL_H_INCLUDED
  11. #define PL_GLOBAL_H_INCLUDED
  12.  
  13. #ifndef ulong
  14. #define ulong unsigned long
  15. #endif
  16.  
  17. #ifndef GLOBAL            /* global variables */
  18. #define GLOBAL extern
  19. #endif
  20.  
  21. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  22. This module packs SWI-Prolog global data-structures into two structures.
  23. The structure PL_global_data contains all global data that is related to
  24. the state of the system as a  whole, and PL_local_data contains all data
  25. that is related to a Prolog thread.
  26. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  27.  
  28.          /*******************************
  29.          *         CODE DATA        *
  30.          *******************************/
  31.  
  32. typedef struct
  33. {
  34. #if VMCODE_IS_ADDRESS
  35.   char   *_dewam_table;            /* decoding table */
  36.   long      _dewam_table_offset;        /* offset of 1st */
  37.   code    _wam_table[I_HIGHEST+1];    /* code --> address */
  38.   void  **_interpreter_jmp_table;    /* interpreters table */
  39. #else
  40.   int      struct_may_not_be_empty;    /* empty structure is illegal */
  41. #endif
  42. } PL_code_data_t;
  43.  
  44.  
  45.          /*******************************
  46.          *        GLOBAL DATA        *
  47.          *******************************/
  48.  
  49. typedef struct
  50. { char *top_of_heap;            /* highest allocated heap address */
  51.   char *base_of_heap;            /* lowest allocated heap address */
  52.   ulong rounded_heap_base;        /* heap-base rounded downwards */
  53.   int    critical;            /* heap is being modified */
  54.   char *cannot_save_program;        /* why program cannot be saved */
  55.   pl_loaderstatus_t _loaderstatus;    /* status of foreign code loader */
  56.   pl_defaults_t        defaults;        /* system default settings */
  57.   pl_options_t        options;        /* command-line options */
  58.   State        stateList;        /* list of loaded states */
  59.   ulong        bases[STG_MASK+1];    /* area base addresses */
  60.   int        initialised;        /* Heap is initialised */
  61.   int        io_initialised;        /* I/O system has been initialised */
  62.   int        bootsession;        /* -b boot compilation */
  63.   int        debug_level;        /* Maintenance debugging: 0..9 */
  64.   int        dumped;            /* Restored saved-state */
  65.   Feature    _feature_list;        /* global features */
  66.  
  67.   struct
  68.   { int        argc;            /* main(int argc, char **argv) */
  69.     char **    argv;
  70.     int        _c_argc;        /* stripped options */
  71.     char **    _c_argv;
  72.     int        notty;            /* -tty: donot use ioctl() */
  73.     int        optimise;        /* -O: optimised compilation */
  74.   } cmdline;
  75.  
  76.   struct
  77.   { long    heap;            /* heap in use */
  78.     int        atoms;            /* No. of atoms defined */
  79.     int        functors;        /* No. of functors defined */
  80.     int        predicates;        /* No. of predicates defined */
  81.     int        modules;        /* No. of modules in the system */
  82.     long    codes;            /* No. of byte codes generated */
  83.   } statistics;
  84.  
  85.   struct
  86.   { Module    user;            /* user module */
  87.     Module    system;            /* system predicate module */
  88.   } modules;
  89.  
  90.   struct
  91.   { Table    modules;        /* atom --> module */
  92.   } tables;
  93.  
  94.   struct
  95.   { buffer    functions;        /* index --> function */
  96.     ArithFunction table[ARITHHASHSIZE];    /* functor --> function table */
  97.   } arith;
  98.  
  99.   struct
  100.   { buffer    array;            /* index --> atom */
  101.     int        buckets;        /* # buckets in char * --> atom */
  102.     int        locked;            /* table is locked */
  103.     Atom *    table;            /* hash-table */
  104. #ifdef O_DEBUG
  105.     int        lookups;        /* # atom lookups */
  106.     int        cmps;            /* # string compares for lookup */
  107. #endif
  108.   } atoms;
  109.  
  110.   struct
  111.   { Table    breakpoints;        /* Breakpoint table */
  112.   } comp;
  113.  
  114.   struct
  115.   { ExtensionCell _ext_head;        /* head of registered extensions */
  116.     ExtensionCell _ext_tail;        /* tail of this chain */
  117.     int          _loaded;        /* system extensions are loaded */
  118.   } foreign;
  119.  
  120.   struct                /* pl-format.c */
  121.   { Table    predicates;
  122.   } format;
  123.  
  124.   struct
  125.   { Table    table;            /* flag key --> flag */
  126.   } flags;
  127.  
  128.   struct
  129.   { buffer    array;            /* index --> functor */
  130.     int        buckets;        /* # buckets in atom --> functor */
  131.     int        locked;            /* table is locked */
  132.     FunctorDef* table;            /* hash-table */
  133.   } functors;
  134.  
  135.   struct
  136.   { Operator    table[OPERATORHASHSIZE]; /* global operator table */
  137.   } op;
  138.  
  139.   struct
  140.   { TempFile        _tmpfile_head;
  141.     TempFile        _tmpfile_tail;
  142.     CanonicalDir    _canonical_dirlist;
  143.     char *        myhome;        /* expansion of ~ */
  144.     char *        fred;        /* last expanded ~user */
  145.     char *        fredshome;    /* home of fred */
  146.     OnHalt        on_halt_list;    /* list of onhalt hooks */
  147.     int            halting;    /* process is shutting down */
  148.     int            prompt_next;    /* prompt on next read operation */
  149.     IOFUNCTIONS        iofunctions;    /* initial IO functions */
  150.     IOFUNCTIONS     org_terminal;    /* IO+Prolog terminal functions */
  151.     IOFUNCTIONS        rl_functions;    /* IO+Terminal+Readline functions */
  152.   } os;
  153.  
  154.   struct
  155.   { Procedure    alt1;            /* $alt/1, see C_OR */
  156.     Procedure    garbage_collect0;
  157.     Procedure     block3;
  158.     Procedure    catch3;
  159.     Procedure    true0;
  160.     Procedure    fail0;
  161.     Procedure    event_hook1;
  162.     Procedure    print_message2;
  163.     Procedure    foreign_registered2;    /* $foreign_registered/2 */
  164.     Procedure    prolog_trace_interception4;
  165.     Procedure    portray;        /* portray/1 */
  166.   } procedures;
  167. } PL_global_data_t;
  168.  
  169.  
  170.          /*******************************
  171.          *         LOCAL DATA        *
  172.          *******************************/
  173.  
  174. typedef struct
  175. { LocalFrame environment;        /* Current local frame */
  176.   FliFrame   foreign_environment;    /* Current foreign context */
  177.   pl_stacks_t stacks;            /* Prolog runtime stacks */
  178. #ifdef HAVE_SIGNAL
  179.   sig_handler sig_handlers[MAXSIGNAL];    /* How Prolog preceives signals */
  180. #endif  
  181.   ulong        pending_signals;    /* PL_signal() pending signals */
  182.   int        aborted;        /* thread asked for abort */
  183.   int        outofstack;        /* thread is out of stack */
  184.   int        autoload;        /* do autoloading */
  185.   int        in_arithmetic;        /* doing arithmetic */
  186.  
  187.   struct
  188.   { atom_t      file;            /* current source file */
  189.     int            line;            /* current line */
  190.     long      character;        /* current character location */
  191.   } read_source;
  192.  
  193.   int     _fileerrors;            /* current file-error status */
  194.   atom_t _float_format;            /* floating point format */
  195.  
  196.   struct
  197.   { term_t    term;            /* exception term */
  198.     term_t    bin;            /* temporary handle for exception */
  199.     term_t    printed;        /* already printed exception */
  200.   } exception;
  201.  
  202.   struct
  203.   { ulong    inferences;        /* inferences in this thread */
  204. #ifdef O_PROFILE
  205.     int        profiling;        /* profiler is on */
  206.     ulong    profile_ticks;        /* profile ticks total */
  207. #endif /* O_PROFILE */
  208.   } statistics;
  209.  
  210.   struct
  211.   { Module    typein;            /* module for type in goals */
  212.     Module    source;            /* module we are reading clauses in */
  213.   } modules;
  214.  
  215.   struct
  216.   { Atom     generator;        /* See PL_atom_generator() */
  217.   } atoms;
  218.  
  219.   struct
  220.   { Assoc    bags;            /* findall/setof bags storage */
  221.   } bags;
  222.  
  223.   struct
  224.   { VarDef *    _vardefs;        /* compiler variable analysis */
  225.     int        _nvardefs;
  226.     int        _filledVars;
  227.   } comp;
  228.  
  229.   struct
  230.   { char *    _CWDdir;
  231.     int        _CWDlen;
  232.   } os;
  233.  
  234.   struct
  235.   { FindData    find;            /* /<ports> <goal> in tracer */
  236.   } trace;
  237.  
  238.   struct
  239.   { AbortHandle    _abort_head;        /* PL_abort_hook() */
  240.     AbortHandle _abort_tail;
  241.     
  242.     InitialiseHandle _initialise_head;    /* PL_initialise_hook() */
  243.     InitialiseHandle _initialise_tail;
  244.  
  245.     PL_dispatch_hook_t _dispatch_events; /* PL_dispatch_hook() */
  246.  
  247.     buffer    _discardable_buffer;    /* PL_*() character buffers */
  248.     buffer    _buffer_ring[BUFFER_RING_SIZE];
  249.     int        _current_buffer_id;
  250.   } fli;
  251.  
  252. #ifdef O_LIMIT_DEPTH
  253.   struct
  254.   { ulong limit;
  255.     ulong reached;
  256.   } depth_info;
  257. #endif
  258.  
  259.   pl_gc_status_t    _gc_status;    /* Garbage collection status */
  260. #ifdef O_SHIFT_STACKS
  261.   pl_shift_status_t    _shift_status;    /* Stack shifter status */
  262. #endif
  263.   
  264.   pl_debugstatus_t _debugstatus;    /* status of the debugger */
  265.   pl_features_t       _features;        /* thread-local features */
  266. } PL_local_data_t;
  267.  
  268. GLOBAL PL_local_data_t  PL_local_data;
  269. GLOBAL PL_global_data_t PL_global_data;
  270. GLOBAL PL_code_data_t    PL_code_data;
  271.  
  272. #define LD (&PL_local_data)
  273. #define GD (&PL_global_data)
  274. #define CD (&PL_code_data)
  275.  
  276. #define hTop            (GD->top_of_heap)
  277. #define hBase            (GD->base_of_heap)
  278. #define heap_base        (GD->rounded_heap_base)
  279. #define loaderstatus        (GD->_loaderstatus)
  280. #define base_addresses        (GD->bases)
  281. #define functor_array        (GD->functors.array)
  282. #define atom_array        (GD->atoms.array)
  283. #define systemDefaults        (GD->defaults)
  284.  
  285. #define environment_frame     (LD->environment)
  286. #define fli_context          (LD->foreign_environment)
  287. #define source_file_name    (LD->read_source.file)
  288. #define source_line_no        (LD->read_source.line)
  289. #define source_char_no        (LD->read_source.character)
  290. #define LD_sig_handler(n)    (LD->sig_handlers[(n)])
  291. #define signalled        (LD->pending_signals)
  292. #define exception_term        (LD->exception.term)
  293. #define exception_bin        (LD->exception.bin)
  294. #define exception_printed    (LD->exception.printed)
  295. #define fileerrors        (LD->_fileerrors)
  296. #define float_format        (LD->_float_format)
  297. #define gc_status        (LD->_gc_status)
  298. #define shift_status        (LD->_shift_status)
  299. #define debugstatus        (LD->_debugstatus)
  300. #define features        (LD->_features)
  301. #define depth_limit        (LD->depth_info.limit)
  302. #define depth_reached        (LD->depth_info.reached)
  303.  
  304. #ifdef VMCODE_IS_ADDRESS
  305. #define dewam_table        (CD->_dewam_table)
  306. #define dewam_table_offset    (CD->_dewam_table_offset)
  307. #define wam_table        (CD->_wam_table)
  308. #define interpreter_jmp_table    (CD->_interpreter_jmp_table)
  309. #endif /*VMCODE_IS_ADDRESS*/
  310.  
  311. #endif /*PL_GLOBAL_H_INCLUDED*/
  312.